package com.wave12.pro_cart.pub;

public enum ErrorCode {
    // USER_ 以能表示功能模块的名称作为前缀
    USER_NAME_EXIST(1000, "用户名已经存在"),
    USER_NAME_PASS_ERROR(1001, "用户名或密码错误"),

    SMS_SEND_ERROR(1000, "短消息发送错误"),
    ADD_MISS_ERROR(1003, "添加失败"),
    UPDATE_MISS_ERROR(1004, "更新失败"),
    SELECT_MISS_ERROR(1005, "查无数据");

    private final Integer code;
    private final String desc;

    ErrorCode(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ErrorCode getInstance(Integer code) {
        if (code != null) {
            for (ErrorCode tmp : ErrorCode.values()) {
                if (tmp.code.intValue() == code.intValue()) {
                    return tmp;
                }
            }
        }
        return null;
    }

    public Integer code() {
        return code;
    }

    public String desc() {
        return desc;
    }
}
